package com.chenchao.collection.stream;

import java.util.ArrayList;

/**
 * @encoding : UTF-8
 * @Time : 2020/12/4 21:05
 * @Author : Chen Chao
 * @File : javaSE.com.chenchao.collection.stream.Test07.java
 * @Software : IntelliJ IDEA
 * @since : 1.8
 * foreach() count()终结流
 */
public class Test07 {
    public static void main(String[] args) {
        ArrayList<String> strings = new ArrayList<>();
        strings.add("an apple");
        strings.add("an apple");
        strings.add("good");
        strings.add("pear");
        strings.add("orange");
        /*foreach终结流*/
        /*这里调用的是Arraylist实现接口的Iterable<T>默认方法foreach*/
        strings.forEach(System.out::println);
        /*count()终结流*/
        long a = strings.stream().filter(s -> s.startsWith("a")).count();
        System.out.println("以a开头的字符串共有"+a+"个");


    }
}
